local CommonOHOH = _G.CommonOHOH;
local M = CommonOHOH.class.new(script, CommonOHOH.files.BaseComponent());

function M.new(self,...)
	return M(self,...);
end;

function M.ctor(self, parent)
	M.super.ctor(self, parent);
    self.gui=self.parent
end;

function M.Init(self,ctrl,player)
	self.player=player
    self.ctrl=ctrl
    self.DataBase=self.player:GetComponent(_G.ClientOHOH.load.Client_PlayerDataComponent())
    self.gui:SetLuckData(self:GetLuckData())
    self.player.UserDataEvent:Connect(function(data)
        if data["gamePass"]   then
            self.gui:SetLuckData(self:GetLuckData())
        end;
    end);

    self.gui.LuckyBuyEvent:Connect(function(id)
        local g="gamepass_pet_luck"..id
        self.player.RobuxBuyEvent:Action(self.ctrl:GetGamePassGoodId(g))
    end)

end

function M.GetLuckData(self)
    local gamePassData=self.DataBase:GetData("gamePass")
    local g1="gamepass_pet_luck1"
    local g2="gamepass_pet_luck2"
    local g3="gamepass_pet_luck3"

   local v1= self.ctrl:GetGamePassValue(g1)
   local v2= self.ctrl:GetGamePassValue(g2)
   local v3= self.ctrl:GetGamePassValue(g3)

   local h1=gamePassData[g1] or false
   local h2=gamePassData[g2] or false
   local h3=gamePassData[g3] or false
   
    return {
       [1]={
            Lucky=v1,
            IsHad=h1,
        },
        [2]={
            Lucky=v2,
            IsHad=h2,
        },
        [3]={
            Lucky=v3,
            IsHad=h3,
        }
    }

end


return M